<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: dialog.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: dialog.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * @module ChiVoxSDK
 * @author Don Li &lt;kai.li@chivox.com>
 * @licence
 * Copyright (c) 2017 - 2020 ChiVox Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import Utils from './utils';
import cfg from './config.json';

const DIALOG_CONTENT = `
&lt;div class="dialogTitle">设置面板&lt;button class="dialogCloseButton">X&lt;/button>&lt;/div>
&lt;div class="dialogFlashError">
  &lt;p class="flashVersion hidden">
  您电脑的Flash版本过低，请点击此链接升级。
  &lt;br/>
  &lt;a href="http://get.adobe.com/flashplayer/" target="_blank">点击下载最新Flash版本&lt;/a>
  &lt;/p>
  &lt;p class="flashPlugin hidden">
  您的电脑没有安装或者禁用Flash插件，请确认。
  &lt;br/>
  &lt;a href="http://get.adobe.com/flashplayer/" target="_blank">点击下载最新Flash版本&lt;/a>
  &lt;/p>
&lt;/div>
&lt;div class="dialogBody">&lt;div id="chivox-recorder">&lt;/div>&lt;/div>
&lt;div class="dialogInfo">
  &lt;h5>状态信息&lt;/h5>
  &lt;ul>
    &lt;li class="loadFlashPlayer hidden">&lt;span class="info">正在下载Flash播放器...&lt;/span>&lt;/li>
    &lt;li class="loadFlashRecorder hidden">&lt;span class="info">正在下载Flash录音机...&lt;/span>&lt;/li>
    &lt;li class="connectServerInit hidden">&lt;span class="error">还没有连接录音服务器&lt;/span>&lt;/li>
    &lt;li class="connectServerStart hidden">&lt;span class="info">正在连接录音服务器，请稍候...&lt;/span>&lt;/li>
    &lt;li class="connectServerSuccess hidden">&lt;span class="success">连接录音服务器成功&lt;/span>&lt;/li>
    &lt;li class="micStatusAllow hidden">&lt;span class="success">Flash可以访问麦克风&lt;/span>&lt;/li>
    &lt;li class="micStatusDisallow hidden">&lt;span class="error">Flash不能访问麦克风，请设置&lt;/span>&lt;/li>
    &lt;li class="micStatusError hidden">&lt;span class="error">没有找到录音设备，请检查&lt;/span>&lt;/li>
  &lt;/ul>
&lt;/div>
&lt;div class="dialogButton">&lt;button class="okButton">确定&lt;/button>&lt;/div>
`;

/**
 * Dialog类。&lt;br/>&lt;/br/>
 *
 * ChiVoxSDK初始化及使用中，需要显示播放器／录音机／网络状态／麦克风相关的状态设置对话框。 &lt;br/>
 * 当以下状态出现时，会弹出对话框：&lt;br/>
 * 1. 开始下载Flash播放器&lt;br/>
 * 2. 开始连接评分服务器&lt;br/>
 * 3. 连接评分服务器失败&lt;br/>
 * 4. Flash插件不可用&lt;br/>
 * 5. 麦克风或录音设备不能使用
 */
class Dialog {
    constructor() {
        this.__ele_overlay = Utils.find(document, cfg.selector.dialogOverlay);
        this.__ele_dialog  = Utils.find(document, cfg.selector.mediadialog);

        if (!(this.__ele_dialog &amp;&amp; this.__ele_overlay)) {
            this.__insert_dialog_elements();
        }

        this.__init = true;
        this.close();
    }

    __insert_dialog_elements() {
        let ele_root = document.createElement('div');

        this.__ele_overlay = document.createElement('div');
        this.__ele_overlay.id = cfg.selector.dialogOverlay.substr(1);
        this.__ele_overlay.setAttribute('class', cfg.selector.dialogOverlay.substr(1));

        this.__ele_dialog = document.createElement('div');
        this.__ele_dialog.id = cfg.selector.mediadialog.substr(1);
        this.__ele_dialog.setAttribute('class', cfg.selector.mediadialog.substr(1));
        this.__ele_dialog.innerHTML = DIALOG_CONTENT;

        ele_root.appendChild(this.__ele_overlay);
        ele_root.appendChild(this.__ele_dialog);

        document.body.appendChild(ele_root);
    }

    /**
     * 打开通用的信息提示框。
     */
    open() {
        if (!this.__init) return;

        this.__ele_overlay.style.display = '';
        //this.__ele_dialog.style.display = '';

        Utils.removeClass(this.__ele_dialog, 'aiMediaDialogClosed');
        Utils.addClass(this.__ele_dialog, 'aiMediaDialogSuccess');
        Utils.addClass(this.__ele_dialog, 'aiMediaDialogError');
    }

    /**
     * 打开Flash相关错误信息提示框。
     */
    open_flash_error() {
        if (!this.__init) return;

        this.__ele_overlay.style.display = '';

        Utils.removeClass(this.__ele_dialog, 'aiMediaDialogClosed');
        Utils.addClass(this.__ele_dialog, 'aiMediaDialogSuccess');
        Utils.addClass(this.__ele_dialog, 'aiMediaDialogError');

        let ele_flashplugin = Utils.find(this.__ele_dialog, '.flashPlugin');
        if (ele_flashplugin) {
            Utils.removeClass(ele_flashplugin, 'hidden');
        }
    }

    /**
     * 关闭当前的信息提示框。
     */
    close() {
        if (!this.__init) return;

        this.__ele_overlay.style.display = 'none';
        //this.__ele_dialog.style.display = 'none';

        Utils.removeClass(this.__ele_dialog, 'aiMediaDialogSuccess');
        Utils.removeClass(this.__ele_dialog, 'aiMediaDialogError');
        Utils.addClass(this.__ele_dialog, 'aiMediaDialogClosed');
    }
}

export default Dialog
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK_flash.html">ChiVoxSDK/flash</a></li><li><a href="module-ChiVoxSDK_html5.html">ChiVoxSDK/html5</a></li><li><a href="module-ChiVoxSDK_lib.html">ChiVoxSDK/lib</a></li><li><a href="module-ChiVoxSDK_Paragraph.html">ChiVoxSDK/Paragraph</a></li><li><a href="module-ChiVoxSDK_score.html">ChiVoxSDK/score</a></li></ul><h3>Classes</h3><ul><li><a href="module-ChiVoxSDK_flash.FlashPlayer.html">FlashPlayer</a></li><li><a href="module-ChiVoxSDK_flash.FlashRecorder.html">FlashRecorder</a></li><li><a href="module-ChiVoxSDK_html5.Html5Player.html">Html5Player</a></li><li><a href="module-ChiVoxSDK_html5.Html5Recorder.html">Html5Recorder</a></li><li><a href="module-ChiVoxSDK_html5-VolumeBar.html">VolumeBar</a></li><li><a href="module-ChiVoxSDK_lib-EnScoreMap.html">EnScoreMap</a></li><li><a href="module-ChiVoxSDK_lib-StatusCode.html">StatusCode</a></li><li><a href="module-ChiVoxSDK_Paragraph-Paragraph.html">Paragraph</a></li><li><a href="module-ChiVoxSDK_score-Char.html">Char</a></li><li><a href="module-ChiVoxSDK_score-CnSentScore.html">CnSentScore</a></li><li><a href="module-ChiVoxSDK_score-CnWordScore.html">CnWordScore</a></li><li><a href="module-ChiVoxSDK_score-EnSentRec.html">EnSentRec</a></li><li><a href="module-ChiVoxSDK_score-EnSentScore.html">EnSentScore</a></li><li><a href="module-ChiVoxSDK_score-EnWordScore.html">EnWordScore</a></li><li><a href="module-ChiVoxSDK_score-Phone.html">Phone</a></li><li><a href="module-ChiVoxSDK_score-Word.html">Word</a></li><li><a href="module-ChiVoxSDK-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK-ControlPanel.html">ControlPanel</a></li><li><a href="module-ChiVoxSDK-Dialog.html">Dialog</a></li><li><a href="module-ChiVoxSDK-PlayerBuilder.html">PlayerBuilder</a></li><li><a href="module-ChiVoxSDK-ProgressBar.html">ProgressBar</a></li><li><a href="module-ChiVoxSDK-RecorderBuilder.html">RecorderBuilder</a></li></ul><h3>Namespaces</h3><ul><li><a href="public.html">public</a></li><li><a href="Utils.html">Utils</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Default_ChiVoxPlayer_Options">Default_ChiVoxPlayer_Options</a></li><li><a href="global.html#Default_ChiVoxRecorder_Options">Default_ChiVoxRecorder_Options</a></li><li><a href="global.html#Default_ChiVoxSDK_Options">Default_ChiVoxSDK_Options</a></li><li><a href="global.html#Default_Paragraph_Options">Default_Paragraph_Options</a></li><li><a href="global.html#get_sig">get_sig</a></li><li><a href="global.html#tts">tts</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Sep 21 2017 16:38:41 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
